package com.wanxi.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class GetVariable {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class<?> aClass = Class.forName("com.wanxi.reflect.Student");
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();
        Field age = aClass.getField("age");
//        System.out.println(age);
        age.set(o,222);
        Object o1 = age.get(o);
        System.out.println(o1);
        Field name = aClass.getDeclaredField("name");
        name.setAccessible(true);
        name.set(o,"aaa");
        Object o2 = name.get(o);
        System.out.println(o2);


    }
}
